var base64 = require("../weui/example/images/base64");
//获取应用实例
const app = getApp()

Page({
  data: {
    userId: null,
    mtArr: [],
    pageNo: 1,
    pageSize: 20,
    display: true,
    lookMore: '数据加载中...',
    wh:0
  },
  todetail: function (e) {
    wx.navigateTo({
      url: '../mtDetail/mtDetail?id=' + e.currentTarget.dataset.id
    })
  },
  onLoad: function () {
    this.setData({
      icon20: base64.icon20,
      icon60: base64.icon60,
      search: this.search.bind(this)
    });
    if (app.globalData.userId) {
      var that = this;
      this.setData({
        userId: app.globalData.userId
      })
      wx.request({
        url: 'https://www.xinhuo.site/api/meeting/list',
        data: {
          pageNo: this.data.pageNo,
          pageSize: this.data.pageSize,
          userId: this.data.userId
        },
        method: 'POST',
        header: {
          'Content-Type': 'application/json'
        },
        success(res) {
          if (res.data.syscode == 0) {
            if (res.data.recordList.length == that.data.pageSize) {
              that.data.lookMore = '-上滑查看更多-'
            }
            else {
              that.data.lookMore = '-没有更多内容-'
            }
            that.data.mtArr = that.data.mtArr.concat(res.data.recordList)
            that.setData({
              mtArr: that.data.mtArr,
              lookMore: that.data.lookMore
            })
          }
          else {
            that.setData({
              lookMore: '-暂无会议-'
            })
          }
        }
      })
    }
  },
  goBack: function(){
    wx.navigateBack({
      delta: 1 //返回的页面数，如果 delta 大于现有页面数，则返回到首页,
    });
  },
  search: function (value) {
    return new Promise((resolve, reject) => {
      if (this.data.i % 2 === 0) {
        setTimeout(() => {
          resolve([{ text: '搜索结果', value: 1 }, { text: '搜索结果2', value: 2 }])
        }, 200)
      } else {
        setTimeout(() => {
          resolve([])
        }, 200)

      }
      this.setData({
        i: this.data.i + 1
      })
    })
  },
  selectResult: function (e) {
    console.log('select result', e.detail)
  },
  moreInfo: function() {
    
  },
  videoErrorCallback(e) {
    console.log('视频错误信息:')
    console.log(e.detail.errMsg)
  },
  onShow: function () {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          "wh": res.windowHeight - 96 -wx.getSystemInfoSync().statusBarHeight
        })
      }
    })
  },
  loadMore() {
    var that = this;
    this.setData({
      pageNo: this.data.pageNo + 1
    });
    wx.request({
      url: 'https://www.xinhuo.site/api/meeting/list',
      data: {
        pageNo: this.data.pageNo,
        pageSize: this.data.pageSize,
        userId: this.data.userId
      },
      method: 'POST',
      header: {
        'Content-Type': 'application/json'
      },
      success(res) {
        if (res.data.syscode == 0) {
          if (res.data.recordList.length == that.data.pageSize) {
            that.data.lookMore = '-上滑查看更多-'
          }
          else {
            that.data.lookMore = '-没有更多内容-'
          }
          that.data.mtArr = that.data.mtArr.concat(res.data.recordList)
          that.setData({
            mtArr: that.data.mtArr,
            lookMore: that.data.lookMore
          })
        }
        else {
          that.setData({
            lookMore: '-没有更多内容-'
          })
        }
      }
    })
  }
})
